<template>
  <div>
    <header>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="选择人员:">
          <el-select v-model="formInline.ple" placeholder="所有人">
            <el-option label="人员一" value="8:00"></el-option>
            <el-option label="人员二" value="9:00"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间:">
          <el-select v-model="formInline.start" placeholder="请选择时间">
            <el-option label="时间一" value="8:00"></el-option>
            <el-option label="时间二" value="9:00"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结束时间:">
          <el-select v-model="formInline.end" placeholder="请选择时间">
            <el-option label="人员一" value="8:00"></el-option>
            <el-option label="人员二" value="9:00"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="物料状态:">
          <el-select v-model="formInline.status" placeholder="请选择时间">
            <el-option label="未使用" value="8:00"></el-option>
            <el-option label="制作中" value="9:00"></el-option>
            <el-option label="已完成" value="8:00"></el-option>
            <el-option label="推广中" value="9:00"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </header>
    <div class="main">
      <!-- 左半区 -->
      <div class="left">
        <div class="left_header">
          <span
            ><div class="title">总消费</div>
            <Echart :chartData="echartData.serve4"></Echart></span
          ><span
            ><div class="title">服务包</div>
            <Echart :chartData="echartData.serve4"></Echart> </span
          ><span
            ><div class="title">制作中物料</div>
            <Echart :chartData="echartData.serve4"></Echart>
          </span>
        </div>
        <div class="left_center">
          <span
            ><div class="title">服务包占比</div>
            <div class="yuan">
              <Echart
                :chartData="echartData.serve1"
                :isAxisChart="false"
              ></Echart></div></span
          ><span
            ><div class="title">制作物料占比</div>
            <div class="yuan">
              <Echart
                :chartData="echartData.serve2"
                :isAxisChart="false"
              ></Echart></div
          ></span>
        </div>
        <div class="left_bottom">
          <div class="title">服务包增量统计</div>
          <Echart :chartData="echartData.serve3"></Echart>
        </div>
      </div>
      <!-- 右半区 -->
      <div class="right">
        <!-- 标题 -->
        <div class="bt">ikun排名</div>
        <!-- 表格 -->
        <Table :ikun="ikun"></Table>
        <!-- 分页 -->
        <div class="page">
          <Pagination @num="num" @num2="num2" :total="kun"></Pagination>
          <!-- 总页数 -->
          <!-- <div class="total">共 {{ total }} 页</div> -->
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Echart from "../../components/Echart.vue";
import Table from "../../components/Table.vue";
import Pagination from "../../components/Pagination.vue";
import { getData } from "../../api/ikun.js";
export default {
  components: { Echart, Table, Pagination },
  data() {
    return {
      formInline: {
        ple: "",
        start: "",
        end: "",
        status: "",
      },
      // 返回的爱坤数据
      ikun: [],
      // 爱坤总数据
      kunData: [],
      // 爱坤总条数
      kun: 1,
      // 爱坤总共页数
      total: "",
      // 传来的爱坤页数
      ys: 1,
      // 传来的爱坤每页条数
      ts: 12,
      // echart数据
      echartData: {
        // 物料制作占比数据
        serve1: {
          series: [
            {
              data: [
                { name: "蔡徐坤", value: 400 },
                { name: "鸡你太美", value: 3300 },
                { name: "ikun", value: 1900 },
                { name: "坤坤", value: 700 },
                { name: "爱坤家族", value: 2700 },
              ],
              type: "pie",
              label: {
                show: true,
                position: "outside",
              },
            },
            {
              data: [
                { name: "蔡徐坤", value: 400 },
                { name: "鸡你太美", value: 3300 },
                { name: "ikun", value: 1900 },
                { name: "坤坤", value: 700 },
                { name: "爱坤家族", value: 2700 },
              ],
              type: "pie",
              // 图形上的文本标签
              label: {
                show: true,
                position: "inside",
                // 显示百分比
                formatter: `{d}%`,
              },
            },
          ],
        },
        // 制作物料占比数据
        serve2: {
          series: [
            {
              data: [
                { name: "鸡坤", value: 1900 },
                { name: "坤子", value: 2100 },
                { name: "爱坤team", value: 2700 },
                { name: "坤坤思密达", value: 3300 },
              ],
              type: "pie",
              label: {
                show: true,
                position: "outside",
              },
            },
            {
              data: [
                { name: "鸡坤", value: 1900 },
                { name: "坤子", value: 2100 },
                { name: "爱坤team", value: 2700 },
                { name: "坤坤思密达", value: 3300 },
              ],
              type: "pie",
              label: {
                show: true,
                position: "inside",
                formatter: `{d}%`,
              },
            },
          ],
        },
        // 服务包增量统计数据
        serve3: {
          xData: [
            {
              data: [
                "爱坤",
                "坤爱",
                "鸡你太美",
                "iKUN",
                "坤坤",
                "美太鸡你",
                "蔡徐坤",
              ],
              type: "category",
            },
          ],
          series: [
            {
              data: [1200, 2000, 1500, 800, 700, 1100, 1300],
              type: "bar",
              label: {
                // 图形上的文本标签
                show: true,
                // 标签内容格式器，支持字符串模板和回调函数两种形式，字符串模板与回调函数返回的字符串均支持用 \n 换行
                formatter: function (params) {
                  // 标签内容
                  return params.value + "\n" + "\n" + params.value / 100 + "%";
                },
                // 标签显示位置
                position: "top",
                // 距离图形元素的距离
                distance: 10,
              },
            },
          ],
        },
        // 折线图
        serve4: {
          xData: [
            {
              data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
            },
          ],
          series: [
            {
              data: [150, 230, 224, 218, 135, 147, 260],
              type: "line",
            },
          ],
        },
      },
    };
  },
  methods: {
    onSubmit() {
      console.log("submit!");
    },
    // 传来的每页条数
    num(val) {
      this.total = Math.ceil(this.kunData.length / val);
      this.ts = val;
      this.ikun = this.kunData.slice((this.ys - 1) * (this.ts + 1), this.ts);
    },
    // 传来的当前页数
    num2(val) {
      this.ys = val;
      this.ikun = this.kunData.slice(
        (this.ys - 1) * this.ts,
        (this.ys - 1) * this.ts + this.ts
      );
    },
  },
  created() {
    const number = async () => {
      const data = await getData();
      this.ikun = data.slice(0, 12);
      this.kunData = data;
      this.kun = data.length;
      this.total = Math.ceil(data.length / 12);
    };
    number();
  },
};
</script>
<style scoped lang="less">
header {
  margin-top: 20px;
  width: 100%;
  height: 60px;
  border: 1px solid #ccc;
  .demo-form-inline {
    margin-left: 20px;
    margin-top: 11px;
  }
}

.main {
  display: flex;
  justify-content: space-around;
  overflow: hidden;
}

.left {
  height: 86%;
  width: 60%;
  margin-top: 30px;
  span {
    border-radius: 10px;
    background-color: #ffffff;
    border: 1px solid #ccc;
  }
  .left_header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-size: 12px;
    height: 200px;
    span {
      width: 300px;
      height: 200px;
    }
  }
  .left_center {
    margin-top: 30px;
    display: flex;
    justify-content: space-between;
    width: 100%;
    height: 300px;
    span {
      position: relative;
      width: 460px;
      height: 200px;
      .yuan {
        position: absolute;
        top: 20px;
        right: 20px;
        width: 460px;
        height: 180px;
      }
    }
  }
  .left_bottom {
    margin-top: -30px;
    width: 100%;
    height: 216px;
    border-radius: 10px;
    background-color: #ffffff;
    border: 1px solid #ccc;
  }
}

.title {
  width: 112px;
  font-size: 12px;
  height: 20px;
  margin-left: 10px;
  margin-top: 10px;
}

.right {
  margin-top: 30px;
  width: 38%;
  border: 1px solid #ccc;
  border-radius: 10px;
  .page {
    top: 20px;
    left: 10px;
    position: relative;
    width: 100%;
  }
  .total {
    position: absolute;
    top: 7px;
    right: -106px;
    width: 60px;
    text-align: center;
    line-height: 20px;
    color: #606266;
    font-weight: 600;
    font-size: 14px;
    height: 20px;
  }
  .bt {
    position: relative;
    left: 0px;
    top: 0px;
    width: 130px;
    height: 40px;
    text-align: center;
    font-size: 20px;
    color: #606266;
    line-height: 40px;
  }
}
</style>
